package com.times.demo.execpiton;

import com.times.demo.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    public <T> Result<T> handleException(HttpRequestMethodNotSupportedException e) {
        log.error("请求方式错误！！！: {}", e.getMessage());
        return Result.fail("请求方式错误！！！");
    }

    @ExceptionHandler(Exception.class)
    public <T> Result<T> handleException(Exception e) {
        return Result.fail(e.getMessage());
    }
}